<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="invertedindex.Search"%>
<%@page import="java.util.Map"%>
<%@page import="java.text.DecimalFormat"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Search</title>
<link href="styles.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>

<div id="heading">
<h1>Reuters Document Search</h1>
</div>

<div id="topsearchform">
<form id="form" name="form" method="get" action="results.jsp">
<input type="text" name="q" id="query" />
<button type="submit">Search</button>
</form>
</div>

<%
String query = request.getParameter("q");
Search search = new Search();
Map<Integer, Double> results = search.query(query);
%>

Search results for: <b><%= request.getParameter("q") %></b> (<%= results.size() %> matches)

<div id="results">
<%
for(Integer docId : results.keySet()){
	Double TF_IDF = results.get(docId);
	DecimalFormat df = new DecimalFormat("0.000");
	out.write("<p><a href=\"html/" + docId + ".html\">" + 
			"Document " + docId + "</a> (TF-IDF Score: " + df.format(TF_IDF) + ")</p>");
}

%>
</div>


<div id="footer">
<p>Copyright (c) 2009 Artur Galiullin and Nan Wu</p>
</div>

</body>
</html>